/**
 * 违规视频管理
 */
Ext.define('Module.wg.WgVideo', {
	extend : 'Ext.panel.Panel',
	alias : 'widget.wgVideo',
	id:'wg-WgVideo',
	layout: 'fit',
	initComponent : function() {
		var me = this;
		
		var store = Ext.create('Ext.data.Store',{
			autoLoad: true,
			fields: ['id','videoId','content','vname','userName','uptime','bjNumber','synpath'],			
			proxy: {
				type: 'ajax',
				url: 'wgVideoAction/getWgVideoList.do',
				reader: {
					root: 'datas',
					totalProperty: 'total'
				}
			}
		});
		
		var grid = Ext.create('Ext.grid.Panel',{
			id:'wgVideoPanel',
			store: store,
			tbar: me.getTbar(),
			selModel: Ext.create('Ext.selection.CheckboxModel'),
			bbar: Ext.create('Ext.PagingToolbar', {
				id: me.id+'-bbar',
				store: store,
				displayInfo: true,
				displayMsg: '显示第 {0} 至 {1} 条记录，共 {2} 条',
	            emptyMsg: "无记录"
			}),
			columns: me.getColumns()
		});
		
		
		me.items = [grid]; 
		
		me.callParent();
	},
	getTbar: function(){
		var me = this;
		return {
			xtype: 'panel',
			border: false,
			height: 25,
			width: '100%',
			bodyPadding: 0-1,
			layout: 'column',
			defaults: {columnWidth: 1,bodyPadding: 0},
			items: [{
				xtype: 'toolbar',
				items: [{
					xtype:"textfield",
					fieldLabel : '任务内容',	
					maxLength:50,
					labelWidth:60,
					width:200
				},{
					xtype:"textfield",
					fieldLabel : '视频名称',	
					maxLength:40,
					//regex: /^[a-zA-Z0-9\u4e00-\u9fa5]+$/,
					//regexText : '不能输入特殊字符',
					labelWidth:60,
					width:200
				},{
	        		iconCls: 'icon-search',
					text: '查询',
					handler: function(){
						var tbar = this.up('toolbar');
						var items = tbar.items.items;
						Ext.getCmp('wgVideoPanel').store.proxy.extraParams = {
							content: items[0].getSubmitValue(),
							vname: items[1].getSubmitValue()
						};
						Ext.getCmp('wgVideoPanel').store.loadPage(1);
					}
				},{
					text: '删除',
					iconCls: 'icon-delete',
					handler: function(){
						var rec = Ext.getCmp('wgVideoPanel').getSelectionModel().getSelection();
						if(rec.length > 0){
							me.deleteWgBj(rec);
						}
						else{
							Ext.Msg.alert('提示', '请选择要删除的信息！');
						}
					}
				}]
			}]
		};
	},
	getColumns: function(){
		var me = this;
		return [{
			text: '任务内容',
			dataIndex: 'content',
			width: 300,
			renderer: function(v, cellmeta, record, rowIndex, columnIndex, store){
				if(v==''){
					return '<lable style="color:blue;">无数据</lable>';
				}
				return v;
			}
		},{
			text: '视频名称',
			dataIndex: 'vname',
			width: 240,
			renderer: function(v, cellmeta, record, rowIndex, columnIndex, store){
				if(v==''){
					return '<lable style="color:blue;">无数据</lable>';
				}
				return v;
			}
		},{
			text: '标记数量',
			dataIndex: 'bjNumber',
			width: 150,
			renderer: function(v, cellmeta, record, rowIndex, columnIndex, store){
				if(v > 0){
					return '<a href="javascript:Ext.getCmp(\''+me.id+'\').showWgInfoWin(\''+record.get('videoId')+'\',\''+record.get('synpath')+'\',\''+record.get('content')+'\',\''+record.get('vname')+'\');" title="点击查看">'+v+'&nbsp;&nbsp;&nbsp;[点击查看]</a>';
				}
				else{
					return '无';
				}
			}
		},{
			text: '上传人',
			dataIndex: 'userName',
			width: 150
		}];
	},
    /**
     * 违规信息窗体   
     * @param videoId 视频id
     * @param synpath 现视频路径
     */
    showWgInfoWin :function(videoId,synpath,content,vname){
    	var rec = Ext.getCmp('wgVideoPanel').getSelectionModel().getSelection()[0];
    	if(content =='' || vname == ''){
    		Ext.Msg.alert('提示', '该记录的任务或视频记录不存在！');
    	}else{
    		Ext.create('Module.wg.WgInfoWindow',{
    			width: 1200,
    			height: 607,
    			title: '违规信息',
    			videoId: rec.data.videoId,
    			synpath:rec.data.synpath
    		}).show();
    	}
    },
    deleteWgBj: function(rec){
		var me = this;
		if(rec){
			Ext.Msg.confirm('提示', '你确定要删除当前信息吗？',function(b){
				if('yes' == b){
					var videoIdArr=[];
					var videonames = [];
					for ( var i = 0; i < rec.length; i++) {
						videoIdArr.push(rec[i].get('videoId'));
						videonames.push(rec[i].get('vname'))
					}
					
					
					Ext.Ajax.request({
					    url: 'wgVideoAction/deleteWgBjBatch.do',
					    params: {
					    	videoIdArr : videoIdArr,
					    	videonames : videonames
					    },
					    success: function(response){
        	    	    	var rs = Ext.decode(response.responseText);
        	    	    	if(rs.rst){
        	    	    		Ext.Msg.alert('提示', '删除成功！');
        	    	    		Ext.getCmp('wgVideoPanel').store.load();
        	    	    	}
        	    	    	else{
        	    	    		Ext.Msg.alert('提示', '删除失败！详情：<br>'+rs.msg);
        	    	    	}
					    }
					});
				}
			});
		}
		else{
			Ext.Msg.alert('提示', '请选择要删除的信息！');
		}
	}
});